package com.xjrsoft.module.customerTwo.barin.t_brain_sub_ccount.service.impl;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xjrsoft.core.tool.utils.StringUtil;
import com.xjrsoft.module.customerTwo.barin.t_brain_sub_ccount.entity.TBrainSubCcount;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.xjrsoft.core.tool.utils.CollectionUtil;
import java.util.ArrayList;
import com.xjrsoft.module.customerTwo.barin.t_brain_sub_ccount.dto.TBrainSubCcountListDto;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xjrsoft.common.page.ConventPage;
import com.xjrsoft.common.page.PageOutput;
import java.util.List;
import com.xjrsoft.module.customerTwo.barin.t_brain_sub_ccount.mapper.TBrainSubCcountMapper;
import com.xjrsoft.module.customerTwo.barin.t_brain_sub_ccount.service.ITBrainSubCcountService;
import com.xjrsoft.core.mp.base.BaseService;
import com.xjrsoft.core.tool.utils.Func;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;

/**
 *  服务实现类
 *
 * @author dongxinhang
 * @since 2024-05-11
 */
@Service
@AllArgsConstructor
public class TBrainSubCcountServiceImpl extends BaseService<TBrainSubCcountMapper, TBrainSubCcount> implements ITBrainSubCcountService {


	@Override
	public IPage<TBrainSubCcount> getPageList(TBrainSubCcountListDto pageListDto) {
		Wrapper<TBrainSubCcount> wrapper = Wrappers.<TBrainSubCcount>query().lambda()
				.like(!StringUtil.isEmpty(pageListDto.getF_Account()), TBrainSubCcount::getFAccount, pageListDto.getF_Account())
				.like(!StringUtil.isEmpty(pageListDto.getF_Telephone()), TBrainSubCcount::getFTelephone, pageListDto.getF_Telephone())
				.eq(!StringUtil.isEmpty(pageListDto.getF_SubAccountRole()), TBrainSubCcount::getFSubaccountrole, pageListDto.getF_SubAccountRole())
				.like(!StringUtil.isEmpty(pageListDto.getF_MerchantId()), TBrainSubCcount::getFMerchantid, pageListDto.getF_MerchantId());
		return this.page(ConventPage.getPage(pageListDto), wrapper);
	}

	@Override
	public String addTBrainSubCcount(TBrainSubCcount tBrainSubCcount) {
		String tBrainSubCcountId = IdWorker.get32UUID();
		tBrainSubCcount.setFId(tBrainSubCcountId);
		boolean isSuccess = this.save(tBrainSubCcount);
		return isSuccess ? tBrainSubCcountId : null;
	}

	@Override
	public boolean updateTBrainSubCcount(String id, TBrainSubCcount tBrainSubCcount) {
		tBrainSubCcount.setFId(id);
		return this.updateById(tBrainSubCcount);
	}

	public boolean delete(String ids) {
		List<String> idList = Func.toStrList(ids);
		if (this.removeByIds(idList)) {
			//删除子账号后，修改用户表F_MerchantId字段
			this.getBaseMapper().deleteUserBySubId(idList);
			return true;
		}
		return false;
	}

}